/** 
  课程成绩变更审核
*/
<template>
  <div class="apply-change-score-container">
    <div style="height: 40px;">
      <el-breadcrumb separator="/" class="float-left" style="padding-top: 8px;">
        <el-breadcrumb-item :to="{ path: '/courseGradeChangeReview' }">
          <span @click="backToMain()">{{ $t('courseGradeChangeReview.courseGradeChangeReview') }}</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t('scoreMangementBase.audit') }}</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="float-right">
        <el-button type="text" @click="backToMain()">{{ $t('common.btn.back') }}</el-button>
      </div>
    </div>
    <el-card shadow="never" v-loading="loading" body-style="padding: 24px;">
      <div class="title">{{ $t('scoreChangeApply.changeDetail') }}</div>
      <el-form :model="changeDialog" ref="changeDialog" label-position="right" label-width="90px">
        <table class="table-style-baseinfos">
          <tbody>
            <tr>
              <td class="text-right-background-color">{{ $t('scoreEntryMana.courseCode') }}：</td>
              <td class="text-left-background-none">{{ basicInfo.courseCode }}</td>
              <td class="text-right-background-color">{{ $t('scoreEntryMana.courseName') }}：</td>
              <td class="text-left-background-none">{{ basicInfo.courseName }}</td>
            </tr>
            <tr>
              <td class="text-right-background-color">{{ $t('scoreEntryMana.courseNum') }}：</td>
              <td class="text-left-background-none">{{ basicInfo.courseNum }}</td>
              <td class="text-right-background-color">{{ $t('scoreEntryMana.courseType') }}：</td>
              <td class="text-left-background-none">{{ basicInfo.courseLabelName }}</td>
            </tr>
            <tr>
              <td class="text-right-background-color">{{ $t('courseScoreMana.entryPerson') }}：</td>
              <td class="text-left-background-none">{{ basicInfo.importUser }}</td>
              <td class="text-right-background-color">{{ $t('scoreEntryMana.entryTime') }}：</td>
              <td class="text-left-background-none">{{ basicInfo.importTime }}</td>
            </tr>
          </tbody>
        </table>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('scoreChangeApply.applyExplanation') + '：'" prop="applyExplanation" :rules="[{ required: true, message: $t('scoreChangeApply.requireApplyExplanation'), trigger: 'blur'}]">
              {{ changeDialog.applyExplanation }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item
              :label="$t('scoreChangeApply.evidence') + '：'" 
              prop="evidence"
              style="margin: 12px 0;"
              :rules="[{ required: true, message: $t('scoreChangeApply.requireEvidence'), trigger: 'change'}]">
                <el-upload
                  v-model="changeDialog.evidence"
                  class="upload-info"
                  action="/api/commonservice/obsfile/uploadfile"
                  :data="uploadConfig.data"
                  :on-exceed="handleExceed"
                  :on-preview="(file) => downloadMaterial(file, 111, 'foreignInstitutionLetter')"
                  accept="application/pdf"
                  :limit="1"
                  :file-list="fileList">
                </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('scoreMangementBase.auditExplanation') + '：'" prop="auditInstructions" :rules="[{ required: true, message: $t('scoreMangementBase.requireAuditExplanation'), trigger: 'blur'}]">
              <el-input type="textarea" :rows="5" :placeholder="$t('common.pla.pleaseInput')" v-model="changeDialog.auditInstructions" :maxlength="500" clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="footer-container">
        <el-button type="danger" @click="reject()">{{ $t('scoreMangementBase.reject') }}</el-button>
        <el-button type="primary" @click="pass()">{{ $t('scoreMangementBase.pass') }}</el-button>
      </div>
    </el-card>
    <el-card shadow="never" v-loading="loading" body-style="padding: 24px;">
      <div class="title">{{ $t('scoreMangementBase.auditProgress') }}</div>
      <edu-table :pagination="false" :tooltipEffect="tooltipEffect" :selection="false" stripe :data="approvalProgressData" size="mini">
        <edu-table-column :label="$t('scoreMangementBase.time')" prop="time">
          <template slot-scope="scope">
            {{ scope.row.time | time }}
          </template>
        </edu-table-column>
        <edu-table-column :label="$t('scoreMangementBase.character')" prop="approvorName">
          <template slot-scope="scope">
            {{ scope.row.approvorName }}({{ scope.row.approvorId }})
          </template>
        </edu-table-column>
        <edu-table-column :label="$t('scoreMangementBase.approvalDepartment')" prop="faculty"></edu-table-column>
        <edu-table-column :label="$t('scoreMangementBase.approvalResults')" prop="result">
          <template slot-scope="scope">
            {{ scope.row.result | result}}
          </template>
        </edu-table-column>
        <edu-table-column :label="$t('scoreMangementBase.approvalInstructions')" prop="content"></edu-table-column>
      </edu-table>
    </el-card>
  </div>
</template>
<script>
import * as INDEX from 'common/src/utils/index';
import scoreManagementApi from 'common/src/api/scoreManagement/scoreManagement';
import { downloadfile } from "common/src/api/upload"
export default {
  components: {
  },
  data () {
    return {
      fileList: [
        {
          url: this.basicInfo.enclosureFileUrl,
          name: this.basicInfo.enclosureFileName,
          uid: this.basicInfo.enclosureFileUrl
        }
      ],
      uploadConfig: {
        data: { bucketname: 'face', folderpath: 'file' },
      },
      approvalProgressData: [],
      changeDialog: {
        applyExplanation: this.basicInfo.changeApplyContent,
        evidence: this.basicInfo.enclosureFileUrl,
        auditInstructions: ''
      },
    }
  },
  props: {
    breadcrumbInfo: {
      type: Object,
      default: () => {}
    },
    basicInfo: {
      type: Object,
      default: () => {}
    }
  },
  filters: {
    result(val) {
      switch(val) {
        case 'COMMIT':
          return '提交'
        case 'Process':
          return '通过'
        case 'Reject':
          return '已驳回'
        case 'Recall':
          return '撤回'
        case 'End':
          return '通过'
        case 'approveNoPass':
          return '未通过'
        default: 
          return val
      }
    },
    time(time) {
      return INDEX.parseTime(time, '{y}-{m}-{d}')
    }
  },
  created() {

  },
  mounted() {
    this.getApproveDetail()
  },
  methods: {
    // 返回主页
    backToMain() {
      this.$emit('refresh-main-page')
    },
    // 文件类方法开始
    downloadMaterial(file, fileNumber, key) {
      if (file.url) {
        downloadfile(file.url);
      } else if (file.status === 'success' && file.response.data) {
        downloadfile(file.response.data[file.name].objectkey)
      }
    },
    // 文件类方法结束
    // 驳回
    reject() {
      this.$refs['changeDialog'].validate((valid) => {
        if (valid) {
          let params = {
            "type": 2,
            "content": this.changeDialog.auditInstructions,
            "id": this.basicInfo.id
          }
          scoreManagementApi.confirmationAudit(params).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('scoreMangementBase.auditSuccessfully'))
              this.$emit('refresh-main-page')
            }
          })
        }
      })
    },
    // 通过
    pass() {
      this.$refs['changeDialog'].validate((valid) => {
        if (valid) {
          let params = {
            "type": 1,
            "content": this.changeDialog.auditInstructions,
            "id": this.basicInfo.id
          }
          scoreManagementApi.confirmationAudit(params).then(res => {
            if (res.code === 200) {
              this.$message({
                type: 'success', 
                message: '审核通过'
              })
              this.$emit('refresh-main-page')
            }
          })
        }
      })
    },
    // 获取审核历史
    getApproveDetail() {
      let params = {
        id: this.basicInfo.id
      }
      scoreManagementApi.getApproveDetail(params).then(res => {
        this.approvalProgressData = res
        if (res.code === 200) {
          this.approvalProgressData = res
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .apply-change-score-container ::v-deep {
    .title {
      margin-bottom: 20px;
      font-weight: bold;
      font-size: 18px;
    }
    .table-style-baseinfos {
      border-collapse: collapse;
      table-layout: fixed;
      word-break: break-all;
      background-color: rgba(210, 212, 214, 1);
      border-width: 0.5px;
      border-style: solid;
      border-color: rgba(210, 212, 214, 1);
      width: 100%;
      font-weight: 401;
      font-style: normal;
      font-size: 14px;
      color: #8896a7;
      margin-bottom: 20px;
    }
    .table-style-baseinfos .text-right-background-color {
      background-color: #edf1f5;
      text-align: right;
    }
    .text-left-background-none {
      text-align: left;
    }
    .table-style-baseinfos td {
      width: 25%;
      background-color: rgba(255, 255, 255, 1);
      border-width: 0.5px;
      border-style: solid;
      border-color: rgba(210, 212, 214, 1);
      font-weight: 401;
      font-style: normal;
      font-size: 14px;
      color: #2b3b4e;
      height: 32px;
      padding: 0 10px;
    }
    .score-container {
      .el-form-item {
        margin: 10px 0;
      }
      .el-form-item__content {
        margin-left: 0!important;
      }
    }
    .footer-container {
      width: 100%;
      text-align: right;
      padding: 15px;
    }
  }
</style>